package create_创建型.prototype_pattern_原型模式;

import java.util.Hashtable;

/**
 * Created with IntelliJ IDEA.
 *
 * @Auther: hihi
 * @Date: 2020/07/03/16:13
 * @Description:
 */
public class ShapeCache {

	private static Hashtable<Integer, Shape> cache = new Hashtable<>();

	static {
		Circle circle = new Circle();
		circle.setId(1);
		cache.put(1, circle);
		Rectange rectange = new Rectange();
		rectange.setId(2);
		cache.put(2, rectange);
	}

	public static Shape getShape(int id) {
		try {
			return (Shape) (cache.get(id).clone());
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
}
